#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
//class Solution {
//public:
//    int area(int* a, int right, int left)
//    {
//        int height = a[left];
//        if (a[left] > a[right])
//            height = right;
//        return (right - left) * height;
//    }
//    int maxArea(vector<int>& height) {
//        int n = height.size();
//        int right = n - 1, left = 0;
//        int s1 = 0, s2 = 0;
//        while (right != left)
//        {
//            if (s1 < s2)
//            {
//                s1 = s2;
//            }
//            if (height[right] > height[left])
//            {
//                s2 = area(&height, right, left);
//                left++;
//            }
//            else
//            {
//                s2 = area(&height, right, left);
//                right--;
//            }
//        }
//    }
//};
class Solution {
public:
    int maxArea(vector<int>& height) {
        int right = height.size() - 1, left = 0;
        int ret = 0;
        while (right > left)
        {
            int v = (right - left) * min(height[right], height[left]);
            if (height[right] > height[left])
            {
                left++;
            }
            else
            {
                right--;
            }
            ret = max(ret, v);
        }
        return ret;
    }
};